using System;
using System.Windows.Input;
using CommunityToolkit.Mvvm.Input;

namespace CANBusTools.ViewModels
{
    public class SpeedControlViewModel : ViewModelBase
    {
        private readonly object _busHelper;

        private string _speed = string.Empty;
        public string Speed
        {
            get => _speed;
            set
            {
                if (_speed != value)
                {
                    _speed = value;
                    OnPropertyChanged(nameof(Speed));
                }
            }
        }

        public ICommand SetSpeedCommand { get; }

        public SpeedControlViewModel(object busHelper)
        {
            _busHelper = busHelper;
            SetSpeedCommand = new RelayCommand(SetSpeed);
        }

        private void SetSpeed()
        {
            if (double.TryParse(Speed, out double speedValue))
            {
                // TODO: 替换为实际调用 _busHelper.SpeedChange(speedValue);
                Console.WriteLine($"Set speed to {speedValue}");
            }
            else
            {
                // 这里可以考虑弹窗提示输入错误，暂时用控制台输出
                Console.WriteLine("Invalid speed input");
            }
        }
    }
}
